package com.atguigu.juc.study.chapter04.locks;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author : leimingchao
 * @date Date : 2022年06月12日 11:21
 */
public class Ticket {

    private int number = 50;

    ReentrantLock lock = new ReentrantLock();

    public void sale() {

        lock.lock();

        try {

            if (number > 0) {
                System.out.println(Thread.currentThread().getName() + "卖出第：" + (number--) + "\t 还剩下：" + number);
            }

        } finally {
            lock.unlock();
        }
    }
}
